package org.example.utils;
import cn.hutool.http.HttpUtil;
import org.springframework.beans.factory.annotation.Value;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.io.File;
import java.util.HashMap;
import java.util.List;

@WebListener
public class MySessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent event) {
        HttpSession session = event.getSession();

        // 在Session创建时执行的代码
        System.out.println();
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
        System.out.println("销毁");
        HttpSession session = event.getSession();
        Object imglist = session.getAttribute("imglist");
        List<String> img=(List<String>)imglist;
        if (img.size()>0){
            for (int i=0;i<img.size();)
            {
                HashMap<String, Object> objectObjectHashMap = new HashMap<>();
                objectObjectHashMap.put("body",img.get(i));
                String post = HttpUtil.get("http://localhost:8080/gitee/del", objectObjectHashMap);
                i++;
                System.out.println(post);
            }
            }
        }
        // 在Session销毁时执行的代码
    }
